<?php

namespace App\Http\Controllers\Admin;

use App\Http\Requests\CreateGoodsNumberLogRequest;
use App\Http\Requests\UpdateGoodsNumberLogRequest;
use App\Repositories\GoodsNumberLogRepository;
use App\Http\Controllers\AppBaseController;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

class GoodsNumberLogController extends AppBaseController
{
    /** @var  GoodsNumberLogRepository */
    private $goodsNumberLogRepository;

    public function __construct(GoodsNumberLogRepository $goodsNumberLogRepo)
    {
        $this->goodsNumberLogRepository = $goodsNumberLogRepo;
    }

    /**
     * Display a listing of the GoodsNumberLog.
     *
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        $this->goodsNumberLogRepository->pushCriteria(new RequestCriteria($request));
        $goodsNumberLogs = $this->goodsNumberLogRepository->all();

        return view('goods_number_logs.index')
            ->with('goodsNumberLogs', $goodsNumberLogs);
    }

    /**
     * Show the form for creating a new GoodsNumberLog.
     *
     * @return Response
     */
    public function create()
    {
        return view('goods_number_logs.create');
    }

    /**
     * Store a newly created GoodsNumberLog in storage.
     *
     * @param CreateGoodsNumberLogRequest $request
     *
     * @return Response
     */
    public function store(CreateGoodsNumberLogRequest $request)
    {
        $input = $request->all();

        $goodsNumberLog = $this->goodsNumberLogRepository->create($input);

        Flash::success('Goods Number Log saved successfully.');

        return redirect(route('goodsNumberLogs.index'));
    }

    /**
     * Display the specified GoodsNumberLog.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $goodsNumberLog = $this->goodsNumberLogRepository->findWithoutFail($id);

        if (empty($goodsNumberLog)) {
            Flash::error('Goods Number Log not found');

            return redirect(route('goodsNumberLogs.index'));
        }

        return view('goods_number_logs.show')->with('goodsNumberLog', $goodsNumberLog);
    }

    /**
     * Show the form for editing the specified GoodsNumberLog.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $goodsNumberLog = $this->goodsNumberLogRepository->findWithoutFail($id);

        if (empty($goodsNumberLog)) {
            Flash::error('Goods Number Log not found');

            return redirect(route('goodsNumberLogs.index'));
        }

        return view('goods_number_logs.edit')->with('goodsNumberLog', $goodsNumberLog);
    }

    /**
     * Update the specified GoodsNumberLog in storage.
     *
     * @param  int              $id
     * @param UpdateGoodsNumberLogRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateGoodsNumberLogRequest $request)
    {
        $goodsNumberLog = $this->goodsNumberLogRepository->findWithoutFail($id);

        if (empty($goodsNumberLog)) {
            Flash::error('Goods Number Log not found');

            return redirect(route('goodsNumberLogs.index'));
        }

        $goodsNumberLog = $this->goodsNumberLogRepository->update($request->all(), $id);

        Flash::success('Goods Number Log updated successfully.');

        return redirect(route('goodsNumberLogs.index'));
    }

    /**
     * Remove the specified GoodsNumberLog from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $goodsNumberLog = $this->goodsNumberLogRepository->findWithoutFail($id);

        if (empty($goodsNumberLog)) {
            Flash::error('Goods Number Log not found');

            return redirect(route('goodsNumberLogs.index'));
        }

        $this->goodsNumberLogRepository->delete($id);

        Flash::success('Goods Number Log deleted successfully.');

        return redirect(route('goodsNumberLogs.index'));
    }
}
